#version 460

#include "../project_matrix.glsl"
#include "../gradient_color.glsl"



//layout(location = 0) in vec2 inPos;
//layout(location = 1) in vec2 inColor;


layout(location = 1) out VS_FS_VERTEX {
	flat vec4	vColorA;
	flat vec4	vColorB;
	flat vec2	Gradient;
	vec2		UV;
};

out gl_PerVertex {
	vec4	gl_Position;
	float	gl_PointSize;
};




vec2 pos[4] = {vec2(0.0, 0.0), vec2(1.0, 0.0), vec2(0.0, 1.0), vec2(1.0, 1.0)};
vec2 gUV[4] = {vec2(0.0, 0.0), vec2(1.0, 0.0), vec2(0.0, -1.0), vec2(1.0, -1.0)};

void main(void){
	mat3x2 mat = m_LP_SD[gl_InstanceIndex];
	
	//vertex_in.InstanceIndex = gl_InstanceIndex;
	//vec4 v = vec4(pos[0], mat[2].y, 1.0);
	vec4 v = vec4(pos[gl_VertexIndex], mat[2].y, 1.0);
	//v.xy = (inPos.xy * mat[2].x) + (mat[1] * inColor.xy);
	v.xy *= mat[1] * mat[2].x;
	
	v.xy += mat[0];
	v.xy *= m_Scale;
	v.xy += m_Loc;

	gl_Position = mat_ProjecView * v;
	gl_PointSize = 1;
	uvec2 color = InstanceColor[gl_InstanceIndex];

	vColorA.r = float((color.x & 0xff000000) >> 24) / 255.0;
	vColorA.g = float((color.x & 0x00ff0000) >> 16) / 255.0;
	vColorA.b = float((color.x & 0x0000ff00) >> 8) / 255.0;
	vColorA.a = float((color.x & 0x000000ff)) / 255.0;

	vColorB.r = float((color.y & 0xff000000) >> 24) / 255.0;
	vColorB.g = float((color.y & 0x00ff0000) >> 16) / 255.0;
	vColorB.b = float((color.y & 0x0000ff00) >> 8) / 255.0;
	vColorB.a = float((color.y & 0x000000ff)) / 255.0;
	
	UV = pos[gl_VertexIndex];
	//UV = ivec2(mat[1] * pos[gl_VertexIndex]);
	Gradient = InstanceGradient[gl_InstanceIndex];
}



